package cn.jisol.controller;


import cn.jisol.ngame.actions.SystemAction;
import cn.jisol.ngame.proto.JNSyncMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@Api(value = "JNGameDemo - API", tags = {"WorldCard - API"})
@RestController
@RequestMapping()
@ResponseBody
public class DemoController {

    @ApiImplicitParams({
            @ApiImplicitParam(name="start",value="帧开始"),
            @ApiImplicitParam(name="end",value="帧结束")
    })
    @ApiOperation(value = "获取帧同步数据")
    @GetMapping("/sync/frame")
    public ResponseEntity<byte[]> getSyncFrame(Integer start, Integer end){

        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", "application/json");

        if(Objects.isNull(SystemAction.frame))
            return ResponseEntity.ok().headers(headers).body(new byte[0]);

        JNSyncMessage.JNFrameInfos infos = SystemAction.frame.vGetFrame(start, end);
        return ResponseEntity.ok().headers(headers).body(infos.toByteArray());
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name="start",value="帧开始"),
            @ApiImplicitParam(name="end",value="帧结束")
    })
    @ApiOperation(value = "获取帧同步数据")
    @GetMapping("/sync/hello")
    public String getSyncHello(Integer start, Integer end){
        return "HelloWorld";
    }

}
